<template>
  <div>
      <!-- 表格区域 -->
      <el-table :data="tableData" border style="width: 100%; height: 70%" :header-cell-style="{background:'#09293e',fontSize:'20px',color:'#fff'}">
        <el-table-column prop="时间" label="时间"></el-table-column>
        <el-table-column prop="经度" label="经度"></el-table-column>
        <el-table-column prop="纬度" label="纬度"></el-table-column>
        <el-table-column prop="距离" label="距离"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="primary" @click="editItem(scope.row)" dialogFormVisible = "false">编 辑</el-button>
            <el-button type="primary" @click="deleteItem(scope.row)" dialogFormVisible = "false">删 除</el-button>
          </template>
        </el-table-column>
      </el-table>

    <!-- 编辑对话框 -->
    <el-dialog title="编辑行" :visible.sync="dialogVisible" width="30%">
      <div>
        <el-form :model="currentRow" label-width="10%">
          <el-form-item label="时间">
            <el-input v-model="currentRow.时间"></el-input>
          </el-form-item>
          <el-form-item label="经度">
            <el-input v-model="currentRow.经度"></el-input>
          </el-form-item>
          <el-form-item label="纬度">
            <el-input v-model="currentRow.纬度"></el-input>
          </el-form-item>
          <el-form-item label="距离">
            <el-input v-model="currentRow.距离"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateItem">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 模拟的数据库数据，需要修改为从实际的数据库获取
const tableData = ref([
  { 时间: '2024-01-01 10:00:00', 经度: 120.12345, 纬度: 30.12345, 距离: 100 },
  { 时间: '2024-01-01 10:05:00', 经度: 120.12545, 纬度: 30.12545, 距离: 105 },
  { 时间: '2024-01-01 10:10:00', 经度: 120.12745, 纬度: 30.12745, 距离: 110 },
  { 时间: '2024-01-01 10:15:00', 经度: 120.12945, 纬度: 30.12945, 距离: 115 },
  { 时间: '2024-01-01 10:20:00', 经度: 120.13145, 纬度: 30.13145, 距离: 120 },
  { 时间: '2024-01-01 10:25:00', 经度: 120.13345, 纬度: 30.13345, 距离: 125 },
  { 时间: '2024-01-01 10:30:00', 经度: 120.13545, 纬度: 30.13545, 距离: 130 },
  { 时间: '2024-01-01 10:35:00', 经度: 120.13745, 纬度: 30.13745, 距离: 135 },
  { 时间: '2024-01-01 10:40:00', 经度: 120.13945, 纬度: 30.13945, 距离: 140 },
  { 时间: '2024-01-01 10:45:00', 经度: 120.14145, 纬度: 30.14145, 距离: 145 },
  { 时间: '2024-01-01 10:50:00', 经度: 120.14345, 纬度: 30.14345, 距离: 150 },
  { 时间: '2024-01-01 10:55:00', 经度: 120.14545, 纬度: 30.14545, 距离: 155 },
  { 时间: '2024-01-01 11:00:00', 经度: 120.14745, 纬度: 30.14745, 距离: 160 },
  // ... 其他数据项
]);

const dialogVisible = ref(false);
const currentRow = ref({});

function deleteItem(row) {
  const index = tableData.value.indexOf(row);
  if (index > -1) {
    tableData.value.splice(index, 1);
  }
}

function editItem(row) {
  currentRow.value = { ...row };
  dialogVisible.value = true;
}

function updateItem() {
  const index = tableData.value.findIndex(item => item.时间 === currentRow.value.时间);
  if (index > -1) {
    tableData.value[index] = { ...currentRow.value };
  }
  dialogVisible.value = false;
}
</script>